using System;
using System.Collections.Generic;
using UnityEngine;

public class GameStartScript : MonoBehaviour
{
	[Serializable]
	public class RoomLookDescriptor
	{
		public RoomLook look;

		public GameObject prefab;
	}

	public GameObject humanPlayerPrefab;

	public GameObject aiPlayerPrefab;

	public GameObject remotePlayerPrefab;

	public GameObject ballPrefab;

	public MatchUI ui;

	public bool loadArena = true;

	public CameraController cameraController;

	public List<RoomLookDescriptor> rooms = new List<RoomLookDescriptor>();

	public float timeScale = 1f;

	private void Awake()
	{
		MatchParameters.MatchParams initParameters = MatchParameters.InitParameters;
		if (loadArena)
		{
			CreateRoom(initParameters.roomLook);
		}
		MatchController matchController = null;
		matchController = ((initParameters.matchType == MatchType.SinglePlayer) ? CreateGameObject<MatchController>() : ((initParameters.matchType != MatchType.MultiPlayer) ? CreateGameObject<MatchController>() : CreateGameObject<MultiplayerMatchController>()));
		SingleTableTennis gameType = CreateGameObject<SingleTableTennis>();
		matchController.Init(this, ui, gameType);
		Time.timeScale = timeScale;
	}

	private void CreateRoom(int roomLook)
	{
		RoomLookDescriptor roomLookDescriptor = GetRoomLookDescriptor(roomLook);
		GameObject gameObject = UnityEngine.Object.Instantiate(roomLookDescriptor.prefab);
	}

	private RoomLookDescriptor GetRoomLookDescriptor(int roomLook)
	{
		return rooms[Mathf.Min(roomLook, rooms.Count - 1)];
	}

	public HumanPlayer CreateHumanPlayer()
	{
		return UnityEngine.Object.Instantiate(humanPlayerPrefab).GetComponent<HumanPlayer>();
	}

	public AiPlayer CreateAiPlayer()
	{
		return UnityEngine.Object.Instantiate(aiPlayerPrefab).GetComponent<AiPlayer>();
	}

	public RemotePlayer CreateRemotePlayer()
	{
		return UnityEngine.Object.Instantiate(remotePlayerPrefab).GetComponent<RemotePlayer>();
	}

	public Ball CreateBall()
	{
		return UnityEngine.Object.Instantiate(ballPrefab).GetComponent<Ball>();
	}

	public T CreateGameObject<T>() where T : MonoBehaviour
	{
		GameObject gameObject = new GameObject(typeof(T).ToString());
		gameObject.transform.parent = base.transform.parent;
		return gameObject.AddComponent<T>();
	}
}
